<?php
/**
 * Created by PhpStorm.
 * Power By Mikkle
 * Email：776329498@qq.com
 * Date: 2017/8/30
 * Time: 9:21
 */

namespace mikkle\util\tp_sapp;

use mikkle\tp_sapp\util\WXBizDataCrypt;

/**
 * 通用通知接口
 */
class SappUtilAction
{
    /**
     * 小程序数据解密
     * @param $sessionKey
     * @param $iv
     * @param $encryptedData
     *
     * @return bool|mixed
     */
   public function SappDecrypt($sessionKey, $iv, $encryptedData)
    {
        $appid = getAppid(getSappAccountId());
        $pc = new WXBizDataCrypt($appid, $sessionKey);
        $errCode = $pc->decryptData($encryptedData, $iv, $data);

        if ($errCode == 0) {
            return json_decode($data, TRUE);
        } else {
            return FALSE;
        }

    }
}